package com.xuecheng.web.exceptions;

import com.xuecheng.commons.enums.ErrorCode;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 *
 * @author 七安
 */
@Component
@RestControllerAdvice
public class GlobalExceptionHandling {
    /**
     * 登陆错误
     * @param businessException 自定义异常类
     * @return 错误信息
     */
    @ExceptionHandler(BusinessException.class)
    public ResponseResult businessException(BusinessException businessException) {
        //获取传进来的错误码
        ErrorCode code = businessException.getErrorCode();
        //返回前端
        return ResponseResult.errorResult(code);
    }
}
